<?php
require_once("conf/db_connection.php");

$trucker_id = $_SESSION['trucker_id_nn'];
$query_truck="SELECT * FROM truck WHERE trucker_id='".$trucker_id."' AND is_deleted='0' ORDER BY is_available DESC";
$result_truck=mysql_query($query_truck);
?>
<html>
<head>
<style type = "text/css">
#hor-minimalist-b {
	background-color: #FFFFFF;
    border-collapse: collapse;
    font-family: Georgia;
    font-size: 12px;
    margin: 10px;
    text-align: center;
    width: 900px;
}
#hor-minimalist-b th {
    border-bottom: 2px solid #5F0C0C ;
    color: #5F0C0C;
    font-size: 12px;
    font-weight: bold;
    padding: 10px 8px;
}
#hor-minimalist-b td {
    border-bottom: 1px solid #888888;
    color: #000000;
    padding: 6px 8px;
}
#hor-minimalist-b tbody tr:hover td {
    //color: #0000CC;
	background-color:#BCC5C6;
}
</style>

<script type='text/javascript'>
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
return new ActiveXObject('Microsoft.XMLHTTP');
}
return null;
}

function checkAvailable(id,stat)
{
if(stat=='0')
{
	var askToggle = confirm("Click ok to set vehicle as available.");
}
if(stat=='1')
{
	var askToggle = confirm("Click ok to set vehicle as unavailable.");
}

if(askToggle)
{
	xmlhttp_toggle=GetXmlHttpObject();
	if (xmlhttp_toggle==null)
	{
	alert ('Your browser does not support AJAX!');
	return;
	}
	var url='update_truck.php';
	url=url+"?id="+id;
	url=url+"&stat="+stat;
	xmlhttp_toggle.onreadystatechange=function (){
		  if (xmlhttp_toggle.readyState==4)
		  {
		  var resp_text = xmlhttp_toggle.responseText;
		  if(resp_text=='1')
		  {
			alert('Vehicle is now available');
		  }
		  else if(resp_text=='0')
		  {
			alert('Vehicle is now unavailable');
		  }
		  parent.redirectFrame("bodyFrame","trucker_truck_list.php");
		  }
		}
	xmlhttp_toggle.open('GET',url,true);
	xmlhttp_toggle.send(null);
}
}
</script>

</head>
<body>
<table border='1' width='900' style='background-color:white;margin-left:auto;margin-right:auto;background-color:#5F0C0C;color:white;font-family:Georgia;font-size:12px'>
<th>TRUCK LIST</th>
</table>

<table id='hor-minimalist-b' border='0' width='900' style='margin-left:auto;margin-right:auto'>
<thead>
<tr>
	<th>&nbsp;</th>
	<th>Plate Number</th>
	<th>Equipment Size</th>
	<th>Equipment Type</th>
	<th>Contact Person</th>
	<th>Contact Number</th>
	<th>Remarks</th>
	<!--<th>Tools </th>-->
</tr>
</thead>
<?php
while($row_truck = mysql_fetch_array($result_truck))
{
if($row_truck['is_available']=="1")
{
	$img_avail = "<img onClick=checkAvailable('".$row_truck['id']."','".$row_truck['is_available']."') src='image/green_btn.png' style='cursor:pointer' title='This vehicle is available. Click to set as unavailble.'>";
}
else if($row_truck['is_available']=="0")
{
	$img_avail = "<img onClick=checkAvailable('".$row_truck['id']."','".$row_truck['is_available']."') src='image/red_btn.png' style='cursor:pointer' title='This vehicle is unavailable. Click to set as available.'>";
}
else if($row_truck['is_available']=="2")
{
	$img_avail = "<img onClick=checkAvailable('".$row_truck['id']."','".$row_truck['is_available']."') src='image/orange_btn.png' style='cursor:pointer' title='This vehicle is in use. Click to set as available.'>";
}
?>
<tbody>
<tr>
	<td style="text-align:left; font-family:Georgia; font-size:12px"><?php echo $img_avail ?></td>
	<td style="text-align:center; font-family:Georgia; font-size:12px">&nbsp;<?php echo $row_truck["plate"] ?>&nbsp;</td>
	<td style="text-align:center; font-family:Georgia; font-size:12px">&nbsp;<?php echo $row_truck["equipment_size"] ?>&nbsp;</td>
	<td style="text-align:center; font-family:Georgia; font-size:12px">&nbsp;<?php echo $row_truck["equipment_type"] ?>&nbsp;</td>
	<td style="text-align:center; font-family:Georgia; font-size:12px">&nbsp;<?php echo $row_truck['contact_person'] ?>&nbsp;</td>
	<td style="text-align:center; font-family:Georgia; font-size:12px">&nbsp;<?php echo $row_truck['contact_cellphone'] ?>&nbsp;</td>
	<td style="text-align:left; font-family:Georgia; font-size:12px">&nbsp;<?php echo $row_truck["remarks"] ?>&nbsp;</td>
	<!--<td style="text-align:left; font-family:Georgia; font-size:12px"><img onClick=checkAvailable('<?php echo $row_truck["id"] ?>') src='image/truck2.png' style='cursor:pointer' title='Available'></td>-->
</tr>
</tbody>
<?php
}
?>
</table>		
</body>
</html>

